<template>
  <Card v-style="'boxstyle_bg_1'" title="相关词">
    <template #header>
      <a-space>
        <a-button type="primary">导出数据</a-button>
      </a-space>
    </template>
    <div class="table">
      <div class="th">
        <p>
          <span>关键词</span>
          <span>长尾词</span>
          <span>竞争度</span>
        </p>
      </div>
      <div class="tb">
        <p v-for="(item,index) in dataList" :key="index">
          <span v-title>{{ item.keyword }}</span>
          <span v-title>{{ item.tail }}</span>
          <span>
            <div class="percent">
              <t class="a" :style="`width: ${item.competition}`" />
              <t class="b" />
            </div>
            <span>{{ item.competition }}</span>
          </span>
        </p>
      </div>
    </div>
  </Card>
</template>

<script lang="ts" setup>
import { ref, onMounted, defineProps, toRefs, watch } from "vue";
import Card from "@/components/Card";
import { bigDataApi } from "@/api/bigData";
import store from "@/store";

let selectWord = ref('');
const dataList = ref([]);

const porps = defineProps({
  keyword: {
    type: String,
    default: ''
  }
})

const { keyword } = toRefs(
  porps
);

watch(
  keyword,
  (e) => {
    console.log(e)
    selectWord = e
    if(e){
      getList()
    }
  },
  {
    immediate: true,
  }
);

async function getList() {
  const result = await bigDataApi.detail({
    token: store.getters.user.token,
    keyword: selectWord
  });
  const { data } = result;
  dataList.value = data['related_word']
}

</script>

<style lang="less" scoped>
.table {
  height: 100%;
  display: flex;
  flex-direction: column;

  .th > p,
  .tb > p {
    padding: 15px 20px;
    font-size: 14px;

    display: flex;
    align-content: center;
    > span {
      width: 33%;
      padding: 0 10px;
      display: inline-block;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  .th {
    color: #cbd2d5;
    font-size: 16px;
  }
  .tb {
    flex: 1;
    overflow-y: auto;
  }
  .tb > p {
    background: #131313;
    border-radius: 5px;
    margin-bottom: 10px;

    .percent {
      width: 70%;
      position: relative;
      display: inline-flex;
      .a {
        padding: 5px 0;
        border-radius: 5px;
        background: linear-gradient(90deg, #5be8ff 0%, #179fe6 100%);
        position: absolute;
        left: 0;
      }
      .b {
        width: 100%;
        padding: 5px 0;
        border-radius: 5px;
        background: #f5f7fa;
        margin-right: 5px;
      }
      .t {
        position: absolute;
      }
    }
  }
}
</style>
